package com.edu.controller;

import com.edu.entity.Major;
import com.edu.service.MajorService;
import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MajorControlle
 * @Description
 * @Author W.Jian
 * @Date 2021/5/22 17:51
 **/
@RestController
@RequestMapping("major")
public class MajorController {

    @Autowired
    MajorService majorService;

    /**
     * 根据学校id添加专业
     */
    @PostMapping ("/insertMajor")
     public Result addMajorBySchool(@RequestBody Major major){
         return majorService.saveMajor(major);
     }

    /**
     * 查询学校对应专业
     */
    @GetMapping("/{schoolId}")
    public Result queryBySchoolId(@PathVariable Integer schoolId){
        return majorService.queryBySchoolId(schoolId);
    }

    /**
     * 查询所有专业
     * @return
     */
    @GetMapping("listAll")
    public Result listAll(){
        List<Major> list = majorService.list();
        return Result.success(list,list.size());
    }

    /**
     * 根据学校id查专业
     * @param schoolId
     * @return
     *//*
    @GetMapping("listBySchoolId")
    public Result listBySchoolId(Long schoolId){
        List<Major> list = majorService.listBySchoolId(schoolId);
        return Result.success(list,list.size());
    }

    *//**
     * 学校添加专业
     * @param majorRefSubject
     * @return
     *//*
    @PostMapping ("insertRef")
    public Result insertRef(@RequestBody MajorRefSubject majorRefSubject){
        return majorService.insert(majorRefSubject);
    }*/

    /**
     * 删除学校对应专业
     */
    @PostMapping("updateDelFlag")
    public Result updateDelFlag(Long majorId){
        return majorService.updateDelFlag(majorId);
    }
}
